﻿//*****************************************************************************
//** Project:PatternWell.PAC
//** Copyright 2011 PatternWell LLC
//** Revision History:
//** Version 1.0 - Initial Release
//*****************************************************************************

namespace PatternWell.PAC
{
    /// <summary>
    /// Base class that implements the logic used by all model classes.
    /// </summary>
    public abstract partial class ModelBase:NotificationBase,IModelResource
    {

        #region Dispose Implementation - Implementation of the disposal helper method (Do not modify)

        /// <summary>
        /// Helper method that releases resources for this class implementation.
        /// </summary>
        /// <param name="disposed">flag that determines if the class has already been disposed.</param>
        protected override void Dispose(bool disposed)
        {
            ReleaseResourcesForModelBase();
            base.Dispose(disposed);
        }

        #endregion

        #region Release Management - Logic used to release resources for this class (Add release logic in the supplied helper methods)

        /// <summary>
        /// Helper method that releases resource for the 'ModelBase' class.
        /// </summary>
        private void ReleaseResourcesForModelBase()
        {
            //Intentinally blank this class does not implement any managed resources in the base.
        }

        #endregion

        #region Initialization logic

        /// <summary>
        /// Called by the controller this provides additional initialization logic to be called after the model has been created. This is implemented as a virtual method so it can be modified.
        /// </summary>
        /// <remarks>
        /// By default this does nothing, you will need to override to provide functionality.
        /// </remarks>
        public virtual void InitializeModel()
        {
            //intentinally blank
        }
        #endregion

        #region Release Management

        /// <summary>
        /// Checks the model to determine if it is in a safe state to release resources.
        /// </summary>
        /// <remarks>
        /// By default it returns true, you will need to override the default implementation to provide check logic.
        /// </remarks>
        /// <returns>If the model can be released or not.</returns>
        public virtual ReleaseInfo CanReleaseResources()
        {
            return new ReleaseInfo { CanRelease = true };
        }

        /// <summary>
        /// Helper method that tells the model to release all resources.
        /// </summary>
        /// <remarks>
        /// This will call the dispose method.
        /// </remarks>
        public void ReleaseResources()
        {
            this.Dispose();
        }

        #endregion
    }
}
